CXX	      := gcc
CXXFLAGS  := -fPIC -g -O3 -MMD -fno-stack-protector -D_FORTIFY_SOURCE=0
OBJDIR	  := build
LDFLAGS   := -fPIC -Wl,-Ttext-segment=0x600000
LDLIBS    := -L./lib -lrt -ldce

LIBSHARED := libdce.so

FILES_OBJ := $(OBJDIR)/ideatest.o

OBJS_SHARED := $(OBJDIR)/ckdes.o $(OBJDIR)/idea.o $(OBJDIR)/lz4.o $(OBJDIR)/libdce.o

$(OBJDIR)/%.o: %.c
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) -c $< -o $@ 

.PHONY: all clean

all: shared idea

shared: $(LIBSHARED)

idea: $(FILES_OBJ)
	@mkdir -p $(@D)
	$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $(OBJDIR)/$@
	@cp $(OBJDIR)/$@ ./bin

$(LIBSHARED): $(OBJS_SHARED)
	@mkdir -p $(@D)
	$(CXX) -shared -fPIC $^ -o $(OBJDIR)/$@
	@cp $(OBJDIR)/$@ ./lib
	
clean:
	rm -rf $(OBJDIR) ./bin/* ./lib/libdce.so 
	







	